<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="no-referrer"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../lib/yzhUpload/control/css/zyUpload.css" type="text/css">
    <style>
        body {
            background-color: #ffffff;
        }

        .aui-upload-box {
            background-color: #fff;
            width: 105px;
            height: 105px;
            padding-top: 5px;
            padding-right: 5px;
        }

        .chose_pic_btn {
            width: 95px;
            height: 95px;
            position: relative;
            display: inline-block;
            background-image: url('');
            box-sizing: border-box;
            background-size: 45px 45px;
            background-position: center center;
            background-repeat: no-repeat;
            background-color: #ededed;
            margin-left: 3.3333%;
            margin-bottom: 12px;
            border-radius: 5px;
        }

        .chose_pic_btn div {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
        }

        .cancel {
            width: 20px;
            height: 20px;
            line-height: 19px;
            border: 1px solid #dbd9d9;
            background-color: #dbd9d9;
            border-radius: 50%;
            position: absolute; /* 父组件赋予属性relative生效 */
            right: 0px; /* 使元素处于右上角-右 */
            top: 0px; /* 使元素处于右上角-上 */
        }

        .cancel::before,
        .cancel::after {
            content: "";
            position: absolute;
            height: 14px;
            width: 2px;
            top: 3px; /* 使X处于圆中心 */
            left: 9px; /* 使X处于圆中心 */
            background-color: #353535;
        }

        .cancel::before {
            transform: rotate(45deg);
        }

        .cancel::after {
            transform: rotate(-45deg);
        }

        .layui-form-select dl {
            top: auto;
            bottom: 36px;
        }

        .zyupload {
            height: auto !important;
        }

        .layui-table th {
            text-align: center;
        }

        .layui-table td {
            text-align: center;
        }

        .layui-form-mid {
            color: red !important;
        }

        .width100 {
            width: 100px;
        }

        .width140 {
            width: 140px;
        }

        .color-block {
            display: inline-block;
            width: 10px;
            height: 10px;
            margin-right: 5px;
            border: 1px solid #ccc;
        }

    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>基本信息</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label required">场景名称</label>
        <div class="layui-input-block">
            <select name="sceneAssetsName" lay-filter="sceneAssetsName">
                <option value="最佳拍档测评任务">最佳拍档测评任务</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">商品编号</label>
        <div class="layui-input-block">
            <input type="text" name="goodsNo" lay-verify="required" lay-reqtext="" placeholder="" value=""
                   class="layui-input" readonly>
        </div>
    </div>
    <!--类型-->
    <div class="layui-form-item" style="display:none;">
        <label class="layui-form-label required">商品类型</label>
        <div class="layui-input-block">
            <input type="text" name="goodsType" id="goodsType" lay-verify="required" lay-reqtext="" placeholder=""
                   value=""
                   class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="goodsName" placeholder="请填写商品名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">所属品牌</label>
        <div class="layui-input-block">
            <input type="text" name="brand" placeholder="请输入商品对应的品牌方" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">品牌等级</label>
        <div class="layui-input-block">
            <select name="brandGrade" lay-filter="brandGrade">
                <option value=''>请选择</option>
                <option value='国际进口'>国际进口</option>
                <option value='国内知名'>国内知名</option>
                <option value='初创成长'>初创成长</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">所属企业</label>
        <div class="layui-input-block">
            <select id="enterprise" name="enterpriseNo" lay-search lay-filter="enterprise">
                <option value=''>请选择所属企业</option>
            </select>
        </div>
        <input type="text" name="enterpriseName" value="" hidden>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品分类</label>
        <div class="layui-input-inline">
            <select id="industry" lay-filter="industry"></select>
        </div>
        <div class="layui-input-inline">
            <select id="classes" lay-filter="classes"></select>
        </div>
        <div class="layui-input-inline">
            <select id="pin" lay-filter="pin"></select>
        </div>
        <input type="text" name="category" value="" hidden>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">供应链分类</label>
        <div class="layui-input-inline">
            <select class="lay-select-search" id="supplyChainCateGory" lay-filter="supplyChainCateGory"></select>
        </div>
        <div class="layui-input-inline">
            <select class="lay-select-search" id="supplyChainType" lay-filter="supplyChainType"></select>
        </div>
        <div class="layui-input-inline">
            <select class="lay-select-search" id="supplyChainSpecificCategory"
                    lay-filter="supplyChainSpecificCategory"></select>
        </div>
        <input type="text" name="supplyChain" value="" hidden>
        <input type="text" name="supplyChainId" value="" hidden>
    </div>
    <div class="layui-form-item" style="padding-left: 40px;">
        <div class="layui-inline">
            <label class="layui-form-label">标题标签</label>
            <div class="layui-input-inline">
                <input type="text" name="productAttribute" placeholder="请填写，如:宝妈最爱(限制5个字符内)" value="" maxlength="5"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">标签颜色</label>
            <div class="layui-input-inline">
                <div class="layui-input-inline" style="width: 120px;">
                    <input type="text" name="attributeColor" value="" readonly placeholder="请选择颜色" class="layui-input"
                           id="attributeColor">
                </div>
                <div class="layui-inline" style="left: -11px;">
                    <div id="attributeColor-form"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品标签</label>
        <div class="layui-input-block">
            <div id="demo1"></div>
            <input type="text" name="goodsTag" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">商品主图</label>
        <div class="layui-input-block">
            <div style="display: flex;flex-wrap: wrap">
                <div id="ad-images" style="display: flex;flex-wrap: wrap"></div>
                <div class="aui-upload-box" onclick="addPic()">
                    <div class="aui-upload-pic">
					<span class="chose_pic_btn">
						<div></div>
					</span>
                    </div>
                </div>
            </div>
            <div id="zy-upload" class="zyupload"></div>
            <input type="text" name="goodsImages" value="" hidden>
        </div>
    </div>

    <!--<div class="layui-form-item layui-form-text">-->
    <!--    <label class="layui-form-label">商品客服</label>-->
    <!--    <div class="layui-input-block">-->
    <!--        <select name="csId" lay-filter="csId"></select>-->
    <!--        <input type="text" name="csName" value="" hidden>-->
    <!--    </div>-->
    <!--</div>-->
    <!--<div class="layui-form-item layui-form-text">-->
    <!--    <label class="layui-form-label required">微信客服</label>-->
    <!--    <div class="layui-input-block">-->
    <!--        <select name="openKfid" lay-filter="openKfid"></select>-->
    <!--    </div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">商品详情</label>
        <div class="layui-input-block">
            <div id="editor" style="margin: 50px 0 50px 0"></div>
            <input type="text" name="detail" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-danger" onclick="emptyDetails()">清空详情</button>
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>价格与库存</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">商品规格</label>
        <div class="layui-input-block">
            <input type="text" name="specification" placeholder="请填写商品规格" value="" class="layui-input">
            <!--商品规格选项-->
        </div>
    </div>
    <div class="layui-form-item" style="padding-left: 40px;">
        <div class="layui-inline layui-form-text" style="width: 70%">
            <label class="layui-form-label">备注内容</label>
            <div class="layui-input-block">
                <input type="text" name="reminderContent" placeholder="自定义下单备注内容（限12个字）" maxlength="12" value=""
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">备注提醒</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="remarkReminder" id="remarkReminderSwitch" lay-filter="remarkReminderSwitch"
                       lay-skin="switch"
                       lay-text="ON|OFF">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">商品库存</label>
        <div class="layui-input-block">
            <input type="text" name="inventory" placeholder="库存不填默认不限" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户限购</label>
        <div class="layui-input-block">
            <input type="number" min="0" name="purchaseQuota" placeholder="不填默认不限" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">玫丽专享价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="discountPrice" lay-verify="required|number" lay-reqtext="" placeholder="请填写玫丽专享价"
                   value="" class="layui-input" onblur="inputDiscountPrice()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">市场价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="goodsPrice" lay-verify="required|number" lay-reqtext="" placeholder="请填写市场价"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">供货价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="supplyPrice" lay-verify="required|number" placeholder="请填写供货价" value=""
                   class="layui-input" onchange="inputSupplyPrice()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">百人团购价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="hundredPrice" lay-verify="required|number" lay-reqtext="" placeholder="请填写百人团购价"
                   value="" class="layui-input" onblur="autoCreateTable()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">千人团购价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="thousandPrice" lay-verify="required|number" lay-reqtext="" placeholder="请填写千人团购价"
                   value="" class="layui-input" onblur="autoCreateTable()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">万人团购价（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="tenThousandPrice" lay-verify="required|number" lay-reqtext=""
                   placeholder="请填写万人团购价" value="" class="layui-input" onblur="autoCreateTable()">
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>物流</legend>
    </fieldset>
    <div class="layui-form-item" id="area-picker">
        <div class="layui-form-label">货源地</div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="province" class="province-selector" data-value="" lay-filter="province-1">
                <option value="">请选择省</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="city" class="city-selector" data-value="" lay-filter="city-1">
                <option value="">请选择市</option>
            </select>
        </div>
        <input type="text" name="originAddr" value="" hidden>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">物流方式</label>
        <div class="layui-input-block">
            <input type="text" name="logistics" placeholder="请填写物流方式" value="快递包邮" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">偏远地区运费补充</label>
        <div class="layui-input-block">
            <input type="text" name="extraFreight" placeholder="请填写" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">发货链接</label>
        <div class="layui-input-block">
            <input type="text" name="shippingLink" placeholder="请输入商品对应的发货连接" value="" class="layui-input">
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>分销利润分配</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label required">分销利润（元）</label>
        <div class="layui-input-block">
            <input type="text" name="distributionProfit" placeholder="请填写分销利润" value="0.00" class="layui-input"
                   readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline" style="padding-left: 40px;">
            <label class="layui-form-label">消费者份额</label>
            <div class="layui-input-inline">
                <input type="text" name="cOroportion" value="90%" lay-verify="required" autocomplete="off"
                       class="layui-input" onblur="inputCOroportion()">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label width140">代理区域服务商份额</label>
            <div class="layui-input-inline">
                <input type="text" name="oOroportion" value="10%" lay-verify="required" placeholder=""
                       autocomplete="off" class="layui-input" onblur="inputOOroportion()">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label width100">平台份额</label>
            <div class="layui-input-inline">
                <input type="text" name="pOroportion" value="0%" lay-verify="required" autocomplete="off"
                       class="layui-input" onblur="inputPOroportion()">
            </div>
            <div style="display: none" class="layui-form-mid layui-word-aux">份额之和等于100%</div>
        </div>
        <input type="text" name="percentageProfit" value="" hidden>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">消费者分享佣金（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="consumerShareReward" placeholder="请填写消费者分享佣金" value="0.00" class="layui-input"
                   readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">代理销售佣金（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="foremanReward" placeholder="请填写代理销售佣金" value="0.00" class="layui-input"
                   readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">玫丽平台利润（￥）</label>
        <div class="layui-input-block">
            <input type="text" name="platformProfit" placeholder="请填写玫丽平台利润" value="0.00" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">团购周期（天）</label>
        <div class="layui-input-block">
            <select name="helpCycle" lay-filter="helpCycle">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="5">5</option>
                <option value="7">7</option>
                <option value="10">10</option>
                <option value="15">15</option>
                <option value="20">20</option>
                <option value="30">30</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">自定义销量</label>
        <div class="layui-input-block">
            <input type="text" name="customSales" placeholder="请填写自定义销量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">商品卖点</label>
        <div class="layui-input-block">
            <textarea placeholder="请填写商品卖点" class="layui-textarea" name="peculiarity"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">帮卖客服</label>
        <div class="layui-input-block">
            <select name="helpCsId" lay-filter="helpCsId"></select>
            <input type="text" name="helpCsName" value="" hidden>
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>团销利润分配</legend>
    </fieldset>
    <div id="tableRes" class="table-overlay">
        <table id="dataTable" lay-filter="dataTable" class="layui-hide"></table>
    </div>
    <div class="layui-form-item layui-form-text">
        <!--百人团购-->
        <input type="text" name="hundredGroup" value="" hidden>
        <input type="text" name="hundredProfit" value="" hidden>
        <input type="text" name="hundredConsumerTranche" value="" hidden>
        <input type="text" name="hundredConsumerCashback" value="" hidden>
        <input type="text" name="hundredOnlineTranche" value="" hidden>
        <input type="text" name="hundredOnlineCashback" value="" hidden>
        <input type="text" name="hundredProviderTranche" value="" hidden>
        <input type="text" name="hundredProviderCashback" value="" hidden>
        <!--千人团购-->
        <input type="text" name="thousandGroup" value="" hidden>
        <input type="text" name="thousandProfit" value="" hidden>
        <input type="text" name="thousandConsumerTranche" value="" hidden>
        <input type="text" name="thousandConsumerCashback" value="" hidden>
        <input type="text" name="thousandOnlineTranche" value="" hidden>
        <input type="text" name="thousandOnlineCashback" value="" hidden>
        <input type="text" name="thousandProviderTranche" value="" hidden>
        <input type="text" name="thousandProviderCashback" value="" hidden>
        <!--万人团购-->
        <input type="text" name="tenThousandGroup" value="" hidden>
        <input type="text" name="tenThousandProfit" value="" hidden>
        <input type="text" name="tenThousandConsumerTranche" value="" hidden>
        <input type="text" name="tenThousandConsumerCashback" value="" hidden>
        <input type="text" name="tenThousandOnlineTranche" value="" hidden>
        <input type="text" name="tenThousandOnlineCashback" value="" hidden>
        <input type="text" name="tenThousandProviderTranche" value="" hidden>
        <input type="text" name="tenThousandProviderCashback" value="" hidden>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认添加</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/common/commonApi.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../js/lay-module/xm-select-master/dist/xm-select.js" charset="utf-8"></script>
<script src="https://unpkg.com/cos-js-sdk-v5/dist/cos-js-sdk-v5.min.js"></script>
<!-- 引用核心层插件 -->
<script type="text/javascript" src="../../lib/yzhUpload/core/zyFile.js"></script>
<!-- 引用控制层插件 -->
<script type="text/javascript" src="../../lib/yzhUpload/control/js/zyUpload.js"></script>
<script>
    let goodsType;
    let editor;
    window.onload = function () {
        goodsType = GetQueryString("type");
        if (isNotNull(goodsType)) {
            $('input[name="goodsType"]').val(goodsType);
            if (goodsType === 'SIGNED') {
                $('input[name="cOroportion"]').val('10%');
                $('input[name="oOroportion"]').val('90%');
                $('input[name="pOroportion"]').val('0%');
            }
        } else {
            const iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        }
        let goods_no = getUuiD(18, "HW");
        $('input[name="goodsNo"]').val(goods_no);
        getCServices("商品/帮卖客服");
        // getCustomerServiceChat();
        // 初始化插件
        $("#zy-upload").zyUpload({
            width: "650px",                 // 宽度
            height: "400px",                 // 宽度
            itemWidth: "120px",                 // 文件项的宽度
            itemHeight: "100px",                 // 文件项的高度
            url: "/upload/UploadAction",  // 上传文件的路径
            multiple: true,                    // 是否可以多个文件上传
            dragDrop: true,                    // 是否可以拖动上传文件
            del: true,                    // 是否可以删除文件
            finishDel: false,  				  // 是否在上传文件完成后删除预览
            /* 外部获得的回调接口 */
            onSelect: function (files, allFiles) {                    // 选择文件的回调方法
                console.info("当前选择了以下文件：");
                console.info(files);
                console.info("之前没上传的文件：");
                console.info(allFiles);
            },
            onDelete: function (file, surplusFiles) {                     // 删除一个文件的回调方法
                console.info("当前删除了此文件：");
                console.info(file);
                console.info("当前剩余的文件：");
                console.info(surplusFiles);
            },
            onSuccess: function (file, response) {                    // 文件上传成功的回调方法
                console.info("此文件上传成功：");
                if (isNotNull(response.url)) {
                    uploadAddToImg(response.url);
                }
            },
            onFailure: function (file) {                    // 文件上传失败的回调方法
                console.info("此文件上传失败：");
                console.info(file);
            },
            onComplete: function (responseInfo) {           // 上传完成的回调方法
                console.info("文件上传完成");
                console.info(responseInfo);
            }
        });
    }

    let xm_select = xmSelect.render({
        el: '#demo1',
        language: 'zn',
        direction: 'up',
        data: [
            {name: '平台推荐', value: '平台推荐'},
            {name: '爆款返场', value: '爆款返场'},
            {name: '网红爆款', value: '网红爆款'},
            {name: '今日必买', value: '今日必买'},
            {name: '新品上市', value: '新品上市'},
            {name: '国际进口', value: '国际进口'},
            {name: '国内知名', value: '国内知名'},
            {name: '初创成长', value: '初创成长'},
            {name: '支持7天无理由', value: '支持7天无理由'},
            {name: '不支持7天无理由', value: '不支持7天无理由'},
            {name: '下单请备注规格', value: '下单请备注规格'},
        ],
        on: function (data) {
            let goods_tag = ''
            if (isNotNull(data.arr) && data.arr.length > 0) {
                for (const i in data.arr) {
                    if (goods_tag == '') {
                        goods_tag = data.arr[i].value
                    } else {
                        goods_tag += "," + data.arr[i].value
                    }
                }
            }
            $('input[name="goodsTag"]').val(goods_tag);
        },
        filterable: true,
        create: function (val, arr) {
            //返回一个创建成功的对象, val是搜索的数据, arr是搜索后的当前页面数据
            return {
                name: val,
                value: val
            }
        }
    })

    layui.use(['layer', 'form', 'layarea', 'colorpicker'], function () {
        var form = layui.form,
            layer = layui.layer,
            colorpicker = layui.colorpicker,
            layarea = layui.layarea,
            $ = layui.$;

        colorpicker.render({
            elem: '#attributeColor-form',
            color: $('#attributeColor').val(),
            predefine: true, // 预定义颜色块
            format: 'hex',
            alpha: false, // 不显示透明度选择
            colors: ['#4aaf47', '#96b13e', '#e75658', '#363636', '#eb6138', '#5c7cee'],
            done: function (color) {
                $('#attributeColor').val(color);
            }
        });

        layarea.render({
            elem: '#area-picker',
            data: {},
            change: function (res) {
                //选择结果
                let area = res.province + "-" + res.city;
                $('input[name="originAddr"]').val(area);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let index = layer.alert("确定提交吗？", {
                title: '提示'
            }, function () {
                let flag = judgePersent();
                if (!flag) {
                    return false;
                }
                let myMsg = layer.msg("正在提交...", {
                    icon: 16,
                    time: -1
                })
                if ($("#remarkReminderSwitch").is(':checked')) {
                    data.field.remarkReminder = '1';
                } else {
                    data.field.remarkReminder = '0';
                }
                $.ajax({
                    type: "post",
                    url: '/goods/add',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json; charset=UTF-8',
                    success: function (req) {
                        if (req.code === '200') {
                            layer.msg("已添加");
                            layer.close(index);
                            // 关闭弹出层
                            setTimeout(function () {
                                layer.close(myMsg);//手动关闭
                                let iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                // 调用父页面的方法
                                let parentWindow = window.parent;
                                parentWindow.reloadTable();
                            }, 1500);
                        } else {
                            layer.msg(req.msg);
                        }

                    },
                    error: function (e) {
                        layer.msg("添加失败");
                        layer.close(myMsg);//手动关闭
                    }
                })

            });

            return false;
        });

        //监听商品客服下拉选择
        form.on('select(csId)', function (dataObj) {
            let csName = $('select[name="csId"]').find("option:selected").text();
            $('input[name="csName"]').val(csName);
        });
        //监听商品客服下拉选择
        form.on('select(helpCsId)', function (dataObj) {
            let helpCsName = $('select[name="helpCsId"]').find("option:selected").text();
            $('input[name="helpCsName"]').val(helpCsName);
        });

    });

    //富文本编辑器
    layui.use(['layer', 'wangEditor'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            wangEditor = layui.wangEditor;

        editor = new wangEditor('#editor');
        editor.customConfig.uploadImgServer = "/meily/upload";
        editor.customConfig.uploadFileName = 'file';
        editor.customConfig.pasteFilterStyle = false;
        editor.customConfig.uploadImgMaxLength = 5;
        editor.customConfig.uploadImgHooks = {
            // 上传超时
            timeout: function (xhr, editor) {
                layer.msg('上传超时！')
            },
            // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式，可使用该配置
            customInsert: function (insertImg, result, editor) {
                console.log(result);
                if (result.code == 200) {
                    var url = result.url;
                    insertImg(url);
                    // url.forEach(function (e) {
                    //     insertImg(e);
                    // })
                } else {
                    layer.msg(result.msg);
                }
            }
        };
        editor.customConfig.customAlert = function (info) {
            layer.msg(info);
        };
        editor.customConfig.onchange = function (html) {
            $('input[name="detail"]').val(html);
        };
        editor.create();
    });

    /**
     * 添加商品主图
     */
    function addPic() {
        layui.use(['layer', 'form'], function () {
            const layer = layui.layer
            layer.prompt({
                title: '请输入图片链接',
                btn: ['确定', '取消'],
                area: ['200px', '20px'],
                formType: 0
            }, function (text, index) {
                let goodsImagesVal = $('input[name="goodsImages"]').val();
                if (isNotNull(text)) {
                    if (isNotNull(goodsImagesVal)) {
                        goodsImagesVal += "," + text;
                    } else {
                        goodsImagesVal = text;
                    }
                    $('input[name="goodsImages"]').val(goodsImagesVal);
                    renderImages(goodsImagesVal);
                } else {
                    layer.msg("图片链接不能为空噢");
                }
                layer.close(index);
            });
        });
    }

    /**
     * 渲染加载的图片
     */
    function renderImages(imageLinks) {
        $("#ad-images").html("");
        if (!isNotNull(imageLinks)) return;
        let html = '';
        let imgs_arr = imageLinks.split(",");
        if (imgs_arr.length > 0) {
            for (const i in imgs_arr) {
                html += '<div style="padding: 5px 10px 15px 0px;position: relative;width: 95px;height: 95px;">' +
                    '                <img width="95px" height="95px" src="' + imgs_arr[i] + '"></img>' +
                    '                <span class="cancel" onclick="delImage(' + i + ')"></span>' +
                    '            </div>';
            }
        }
        $("#ad-images").html(html);
    }

    /**
     * 删除图片
     */
    function delImage(index) {
        let image_val = $('input[name="goodsImages"]').val();
        let new_image_val = '';
        if (isNotNull(image_val)) {
            let imgs_arr = image_val.split(",");
            if (imgs_arr.length > 0) {
                for (const i in imgs_arr) {
                    if (i == index) {
                        continue;
                    }
                    if (isNotNull(new_image_val)) {
                        new_image_val += "," + imgs_arr[i];
                    } else {
                        new_image_val = imgs_arr[i];
                    }
                }
            }
        }
        $('input[name="goodsImages"]').val(new_image_val);
        renderImages(new_image_val);
    }

    // 初始化企业列表
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;
        let enterpriseName = ''
        let res = getEnterpriseList();
        res.then(list => {
            if (list.length === 0) {
                return;
            }
            let $html = "";
            for (const index in list) {
                $html += "<option value='" + list[index].enterpriseNo + "'>" + list[index].enterpriseName + "</option>";
            }
            $("#enterprise").append($html);
            form.render('select');
        })
        form.on('select(enterprise)', function (dataObj) {
            enterpriseName = $("#enterprise").find("option:selected").text();
            let value = $("#enterprise").val();
            if (!isNotNull(value)) {
                enterpriseName = '';
            }
            $('input[name="enterpriseName"]').val(enterpriseName);
        });
    })

    //商品分类下拉框
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;
        let industryText = "";
        let classesText = "";
        let pinText = "";

        //异步加载下拉框数据
        $.get("/goods/category/list/root", {}, function (data) {
            if (data.code != 200) {
                layer.msg(data.msg)
            } else {
                let $html = "";
                if (data.rows != null) {
                    $.each(data.rows, function (index, item) {
                        $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                    });
                    $("#industry").append($html);
                    //append后必须从新渲染
                    form.render('select');
                }
            }
        });
        //监听行业下拉框
        form.on('select(industry)', function (dataObj) {
            //移除城市下拉框所有选项
            $("#classes").empty();
            let classesHtml = '<option value="">请选择类目</option>';
            $("#classes").html(classesHtml);
            let pinHtml = '<option value="">请选择品类</option>';
            $("#pin").html(pinHtml);
            industryText = $("#industry").find("option:selected").text();
            let value = $("#industry").val();
            $('input[name="category"]').val(industryText);
            //异步加载下拉框数据
            $.get("/goods/category/list/" + value, function (data) {
                if (data.code != 200) {
                    layer.msg(data.msg)
                } else {
                    let $html = "";
                    if (data.rows != null) {
                        $.each(data.rows, function (index, item) {
                            $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                        });
                        $("#classes").append($html);
                        //append后必须从新渲染
                        form.render('select');
                    }
                }
            });
        });
        //监听类目下拉框
        form.on('select(classes)', function (dataObj) {
            //移除县区下拉框所有选项
            $("#pin").empty();
            let html = '<option value="">请选择品类</option>';
            $("#pin").html(html);
            classesText = $("#classes").find("option:selected").text();
            let value = $("#classes").val();
            let category = industryText + "-" + value;
            $('input[name="category"]').val(category);
            //异步加载下拉框数据
            $.get("/goods/category/list/" + value, function (data) {
                if (data.code != 200) {
                    layer.msg(data.msg)
                } else {
                    let $html = "";
                    if (data.rows != null) {
                        $.each(data.rows, function (index, item) {
                            $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                        });
                        $("#pin").append($html);
                        //append后必须从新渲染
                        form.render('select');
                    }
                }
            });
        });

        //监听品类下拉框
        form.on('select(pin)', function (dataObj) {
            pinText = $("#pin").find("option:selected").text();
            let category = industryText + "-" + classesText + "-" + pinText;
            $('input[name="category"]').val(category);
        });

    });

    // 初始化 供应商下拉列表
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;
        let supplyChainCateGoryText = "";
        let supplyChainTypeText = "";
        let supplyChainSpecificCategoryText = "";

        //异步加载下拉框数据
        let res = getSupplyChainList('0')
        res.then((list) => {
            if (list.length === 0) {
                return;
            }
            let $html = "";
            $html += "<option value=''>" + '请选择分类' + "</option>";
            for (const index in list) {
                $html += "<option value='" + list[index].id + "'>" + list[index].name + "</option>";
            }
            $("#supplyChainCateGory").append($html);
            form.render('select');
        })

        // 监听供应链分类下拉框
        form.on('select(supplyChainCateGory)', function (dataObj) {
            $("#supplyChainType").empty();
            let classesHtml = '<option value="">请选择类目</option>';
            $("#supplyChainType").html(classesHtml);
            let pinHtml = '<option value="">请选择品类</option>';
            $("#supplyChainSpecificCategory").html(pinHtml);
            supplyChainCateGoryText = $("#supplyChainCateGory").find("option:selected").text();
            let value = $("#supplyChainCateGory").val();
            $('input[name="supplyChain"]').val(supplyChainCateGoryText);
            $('input[name="supplyChainId"]').val(value);
            //异步加载下拉框数据
            if (!isNotNull(value)) {
                $('input[name="supplyChain"]').val('');
                $('input[name="supplyChainId"]').val('');
                return;
            }
            let res = getSupplyChainList(value)
            res.then((list) => {
                if (list.length === 0) {
                    return;
                }
                let $html = "";
                for (const index in list) {
                    $html += "<option value='" + list[index].id + "'>" + list[index].name + "</option>";
                }
                $("#supplyChainType").append($html);
                form.render('select');
            })
        });
        //监听类目下拉框
        form.on('select(supplyChainType)', function (dataObj) {
            $("#supplyChainSpecificCategory").empty();
            let html = '<option value="">请选择品类</option>';
            $("#supplyChainSpecificCategory").html(html);
            supplyChainTypeText = $("#supplyChainType").find("option:selected").text();
            let value = $("#supplyChainType").val();
            let supplyChain = supplyChainCateGoryText + "-" + value;
            $('input[name="supplyChain"]').val(supplyChain);
            $('input[name="supplyChainId"]').val(value);
            let res = getSupplyChainList(value)
            res.then((list) => {
                if (list.length === 0) {
                    return;
                }
                let $html = "";
                for (const index in list) {
                    $html += "<option value='" + list[index].id + "'>" + list[index].name + "</option>";
                }
                $("#supplyChainSpecificCategory").append($html);
                form.render('select');
            })
        });

        //监听品类下拉框
        form.on('select(supplyChainSpecificCategory)', function (dataObj) {
            supplyChainSpecificCategoryText = $("#supplyChainSpecificCategory").find("option:selected").text();
            let value = $("#supplyChainSpecificCategory").val();
            let supplyChain = supplyChainCateGoryText + "-" + supplyChainTypeText + "-" + supplyChainSpecificCategoryText;
            $('input[name="supplyChain"]').val(supplyChain);
            $('input[name="supplyChainId"]').val(value);
        });

    });

    /**
     * 获取客服列表
     */
    function getCServices(csType) {
        $.ajax({
            type: "post",
            url: '/clientele/list',
            data: JSON.stringify({csType: csType}),
            dataType: 'json',
            contentType: 'application/json',
            success: function (req) {
                if (req.code == 200 && isNotNull(req.rows) && req.rows.length > 0) {
                    let $html = "";
                    for (const i in req.rows) {
                        if (i == 0) {//初始化时赋值
                            // $('input[name="csName"]').val(req.rows[i].csName);
                            $('input[name="helpCsName"]').val(req.rows[i].csName);
                        }
                        $html += "<option value='" + req.rows[i].csId + "'>" + req.rows[i].csName + "</option>";
                    }
                    $('select[name="csId"]').append($html);
                    $('select[name="helpCsId"]').append($html);
                    layui.use(['form', 'layer', 'jquery'], function () {
                        let form = layui.form;
                        form.render('select');
                    })
                }
            },
            error: function (e) {

            }
        })
    }

    /**
     * 获取微信客服
     */
    function getCustomerServiceChat() {
        $.ajax({
            type: "post",
            url: '/qyapi/kf/account/list',
            dataType: 'json',
            contentType: 'application/json',
            success: function (req) {
                if (req.code == 200 && isNotNull(req.rows) && req.rows.length > 0) {
                    let $html = "<option value=''>请选择</option>";
                    for (const i in req.rows) {
                        $html += "<option value='" + req.rows[i].openKfid + "'>" + req.rows[i].name + "</option>";
                    }
                    $('select[name="openKfid"]').append($html);
                    layui.use(['form', 'layer', 'jquery'], function () {
                        let form = layui.form;
                        form.render('select');
                    })
                }
            },
            error: function (e) {

            }
        })
    }

    /**
     * 生成一个用不重复的ID
     */
    function getUuiD(length, preffix) {
        //timestamp为当前时间戳
        let timestamp = (new Date()).getTime()
        length = length - 13;
        let str = "";
        let str_arr = [
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
        for (let i = 0; i < length; i++) {
            let r = parseInt(Math.random() * 9);//生成0-62之间的随机数
            str += str_arr[r];
        }
        let res_str = preffix + str + timestamp
        return res_str;
    }

    /**
     * 上传文件完成后将文件地址添加到图片列表中
     * @param url
     */
    function uploadAddToImg(url) {
        let goodsImagesVal = $('input[name="goodsImages"]').val();
        if (isNotNull(url)) {
            if (isNotNull(goodsImagesVal)) {
                goodsImagesVal += "," + url;
            } else {
                goodsImagesVal = url;
            }
            $('input[name="goodsImages"]').val(goodsImagesVal);
            renderImages(goodsImagesVal);
        }
    }


    if (!isNotNull(goodsType)) {
        goodsType = GetQueryString("type");
    }

    console.log(goodsType)

    //准备视图对象
    window.viewObj = {
        tbData: [
            {
                groupSalesScale: '百人团',
                groupSalesProfit: '',
                // share1: '80%',
                share1: goodsType === 'SIGNED' ? '10%' : '80%',
                cashBackAmount: '',
                // share2: '10%',
                share2: goodsType === 'SIGNED' ? '80%' : '10%',
                rebateAmount: '',
                // share3: '10%',
                share3: goodsType === 'SIGNED' ? '10%' : '10%',
                rewardAmount: ''
            },
            {
                groupSalesScale: '千人团',
                groupSalesProfit: '',
                share1: '',
                cashBackAmount: '',
                share2: '',
                rebateAmount: '',
                share3: '',
                rewardAmount: ''
            },
            {
                groupSalesScale: '万人团',
                groupSalesProfit: '',
                share1: '',
                cashBackAmount: '',
                share2: '',
                rebateAmount: '',
                share3: '',
                rewardAmount: ''
            }
        ]
    };

    var tableIns;
    layui.use(['jquery', 'table', 'layer'], function () {
        let $ = layui.$, table = layui.table, form = layui.form, layer = layui.layer;

        //数据表格实例化
        var tbWidth = $("#tableRes").width();
        var layTableId = "layTable";
        tableIns = table.render({
            elem: '#dataTable',
            id: layTableId,
            data: viewObj.tbData,
            width: tbWidth,
            loading: true,
            even: false, //不开启隔行背景
            cols: [[
                {field: 'groupSalesScale', title: '团销规模', rowspan: 2} //rowspan即纵向跨越的单元格数
                , {field: 'groupSalesProfit', title: '团销利润（￥）', rowspan: 2}
                , {align: 'center', title: '消费者返现', colspan: 2} //colspan即横跨的单元格数，这种情况下不用设置field和width
                , {align: 'center', title: '代理区域服务商返利', colspan: 2}
                , {align: 'center', title: '选址区域服务商奖励', colspan: 2}
            ], [
                {field: 'share1', title: '份额', edit: 'text'}
                , {field: 'cashBackAmount', title: '返现金额（￥）'}
                , {field: 'share2', title: '份额', edit: 'text'}
                , {field: 'rebateAmount', title: '返利金额（￥）'}
                , {field: 'share3', title: '份额', edit: 'text'}
                , {field: 'rewardAmount', title: '奖励金额（￥）'}
            ]],
            done: function (res, curr, count) {
                $(".layui-table").find('tr[data-index="1"]').find('td').data('edit', false)
                $(".layui-table").find('tr[data-index="2"]').find('td').data('edit', false)
            }
        });

        table.on('edit(dataTable)', function (obj) {
            let oldData = table.cache[layTableId];
            let groupSalesProfit0 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="hundredPrice"]').val())
            let groupSalesProfit1 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="thousandPrice"]').val())
            let groupSalesProfit2 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="tenThousandPrice"]').val())
            oldData[0].groupSalesProfit = groupSalesProfit0.toFixed(2)
            oldData[1].groupSalesProfit = groupSalesProfit1.toFixed(2)
            oldData[2].groupSalesProfit = groupSalesProfit2.toFixed(2)
            if (obj.field == 'share1') {
                let share1 = obj.data.share1;
                let persent = share1.replace("%", "") / 100;
                for (const i in oldData) {
                    oldData[i].share1 = share1
                    let cashBackAmount = parseFloat(oldData[i].groupSalesProfit) * persent
                    oldData[i].cashBackAmount = cashBackAmount.toFixed(2)
                }
            } else if (obj.field == 'share2') {
                let share2 = obj.data.share2;
                let persent = share2.replace("%", "") / 100;
                for (const i in oldData) {
                    oldData[i].share2 = share2
                    let rebateAmount = parseFloat(oldData[i].groupSalesProfit) * persent
                    oldData[i].rebateAmount = rebateAmount.toFixed(2)
                }
            } else if (obj.field == 'share3') {
                let share3 = obj.data.share3;
                let persent = share3.replace("%", "") / 100;
                for (const i in oldData) {
                    oldData[i].share3 = share3
                    let rewardAmount = parseFloat(oldData[i].groupSalesProfit) * persent
                    oldData[i].rewardAmount = rewardAmount.toFixed(2)
                }
            }
            tableIns.reload({
                data: oldData
            });
            tabledataIntoForm();
            console.log(3333)
        })
    })

    /**
     * 输入玫丽专享价，如果百人团购价、千人团购价、万人团购价为空则跟玫丽专享价一样
     */
    function inputDiscountPrice() {
        let discountPrice = $('input[name="discountPrice"]').val()
        if (!isNotNull($('input[name="hundredPrice"]').val())) {
            $('input[name="hundredPrice"]').val(discountPrice)
        }
        if (!isNotNull($('input[name="thousandPrice"]').val())) {
            $('input[name="thousandPrice"]').val(discountPrice)
        }
        if (!isNotNull($('input[name="tenThousandPrice"]').val())) {
            $('input[name="tenThousandPrice"]').val(discountPrice)
        }
        //计算分销利润
        if (isNotNull(discountPrice)) {
            if (isNotNull($('input[name="supplyPrice"]').val())) {
                let distributionProfit = parseFloat(discountPrice) - parseFloat($('input[name="supplyPrice"]').val())
                $('input[name="distributionProfit"]').val(distributionProfit.toFixed(2))
                if (isNotNull($('input[name="cOroportion"]').val())) {
                    let consumerShareReward = parseFloat(distributionProfit) * ($('input[name="cOroportion"]').val().replace("%", "") / 100)
                    $('input[name="consumerShareReward"]').val(consumerShareReward.toFixed(2))
                }
                if (isNotNull($('input[name="oOroportion"]').val())) {
                    let foremanReward = parseFloat(distributionProfit) * ($('input[name="oOroportion"]').val().replace("%", "") / 100)
                    $('input[name="foremanReward"]').val(foremanReward.toFixed(2))
                }
                if (isNotNull($('input[name="pOroportion"]').val())) {
                    let platformProfit = parseFloat(distributionProfit) * ($('input[name="pOroportion"]').val().replace("%", "") / 100)
                    $('input[name="platformProfit"]').val(platformProfit.toFixed(2))
                }
            }
        }

        //生成表格
        autoCreateTable();
    }

    /**
     * 输入供货价
     */
    function inputSupplyPrice() {
        //计算分销利润
        if (isNotNull($('input[name="discountPrice"]').val())) {
            if (isNotNull($('input[name="supplyPrice"]').val())) {
                let distributionProfit = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="supplyPrice"]').val())
                $('input[name="distributionProfit"]').val(distributionProfit.toFixed(2))
                if (isNotNull($('input[name="cOroportion"]').val())) {
                    let consumerShareReward = parseFloat(distributionProfit) * ($('input[name="cOroportion"]').val().replace("%", "") / 100)
                    $('input[name="consumerShareReward"]').val(consumerShareReward.toFixed(2))
                }
                if (isNotNull($('input[name="oOroportion"]').val())) {
                    let foremanReward = parseFloat(distributionProfit) * ($('input[name="oOroportion"]').val().replace("%", "") / 100)
                    $('input[name="foremanReward"]').val(foremanReward.toFixed(2))
                }
                if (isNotNull($('input[name="pOroportion"]').val())) {
                    let platformProfit = parseFloat(distributionProfit) * ($('input[name="pOroportion"]').val().replace("%", "") / 100)
                    $('input[name="platformProfit"]').val(platformProfit.toFixed(2))
                }
            }
        }
    }

    /**
     * 输入消费者比例
     */
    function inputCOroportion() {
        let cOroportion = $('input[name="cOroportion"]').val()
        let distributionProfit = $('input[name="distributionProfit"]').val()
        if (isNotNull(distributionProfit) && isNotNull(cOroportion)) {
            cOroportion = cOroportion.replace("%", "") / 100
            let consumerShareReward = parseFloat(distributionProfit) * parseFloat(cOroportion)
            $('input[name="consumerShareReward"]').val(consumerShareReward.toFixed(2))
            tabledataIntoForm();
        }
    }

    /**
     * 输入线上服务商比例
     */
    function inputOOroportion() {
        let oOroportion = $('input[name="oOroportion"]').val()
        let distributionProfit = $('input[name="distributionProfit"]').val()
        if (isNotNull(distributionProfit) && isNotNull(oOroportion)) {
            oOroportion = oOroportion.replace("%", "") / 100
            let foremanReward = parseFloat(distributionProfit) * parseFloat(oOroportion)
            $('input[name="foremanReward"]').val(foremanReward.toFixed(2))
            tabledataIntoForm();
        }
    }

    /**
     * 输入玫丽平台比例
     */
    function inputPOroportion() {
        let pOroportion = $('input[name="pOroportion"]').val()
        let distributionProfit = $('input[name="distributionProfit"]').val()
        if (isNotNull(distributionProfit) && isNotNull(pOroportion)) {
            pOroportion = pOroportion.replace("%", "") / 100
            let platformProfit = parseFloat(distributionProfit) * parseFloat(pOroportion)
            $('input[name="platformProfit"]').val(platformProfit.toFixed(2))
            tabledataIntoForm();
        }
    }

    /**
     * 将表格数据放入表单中
     */
    function tabledataIntoForm() {
        let tableData = viewObj.tbData;
        $('input[name="hundredGroup"]').val(tableData[0].groupSalesScale)
        $('input[name="hundredProfit"]').val(tableData[0].groupSalesProfit)
        $('input[name="hundredConsumerTranche"]').val(tableData[0].share1)
        $('input[name="hundredConsumerCashback"]').val(tableData[0].cashBackAmount)
        $('input[name="hundredOnlineTranche"]').val(tableData[0].share2)
        $('input[name="hundredOnlineCashback"]').val(tableData[0].rebateAmount)
        $('input[name="hundredProviderTranche"]').val(tableData[0].share3)
        $('input[name="hundredProviderCashback"]').val(tableData[0].rewardAmount)

        $('input[name="thousandGroup"]').val(tableData[1].groupSalesScale)
        $('input[name="thousandProfit"]').val(tableData[1].groupSalesProfit)
        $('input[name="thousandConsumerTranche"]').val(tableData[1].share1)
        $('input[name="thousandConsumerCashback"]').val(tableData[1].cashBackAmount)
        $('input[name="thousandOnlineTranche"]').val(tableData[1].share2)
        $('input[name="thousandOnlineCashback"]').val(tableData[1].rebateAmount)
        $('input[name="thousandProviderTranche"]').val(tableData[1].share3)
        $('input[name="thousandProviderCashback"]').val(tableData[1].rewardAmount)

        $('input[name="tenThousandGroup"]').val(tableData[2].groupSalesScale)
        $('input[name="tenThousandProfit"]').val(tableData[2].groupSalesProfit)
        $('input[name="tenThousandConsumerTranche"]').val(tableData[2].share1)
        $('input[name="tenThousandConsumerCashback"]').val(tableData[2].cashBackAmount)
        $('input[name="tenThousandOnlineTranche"]').val(tableData[2].share2)
        $('input[name="tenThousandOnlineCashback"]').val(tableData[2].rebateAmount)
        $('input[name="tenThousandProviderTranche"]').val(tableData[2].share3)
        $('input[name="tenThousandProviderCashback"]').val(tableData[2].rewardAmount)

        //利润分配
        let percentageProfit = $('input[name="cOroportion"]').val() + '-' + $('input[name="oOroportion"]').val() + '-' + $('input[name="pOroportion"]').val()
        console.log(percentageProfit)
        $('input[name="percentageProfit"]').val(percentageProfit)
    }

    /**
     * 自动生成表格
     */
    function autoCreateTable() {
        let oldData = viewObj.tbData;
        let groupSalesProfit0 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="hundredPrice"]').val())
        let groupSalesProfit1 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="thousandPrice"]').val())
        let groupSalesProfit2 = parseFloat($('input[name="discountPrice"]').val()) - parseFloat($('input[name="tenThousandPrice"]').val())
        oldData[0].groupSalesProfit = groupSalesProfit0.toFixed(2)
        oldData[1].groupSalesProfit = groupSalesProfit1.toFixed(2)
        oldData[2].groupSalesProfit = groupSalesProfit2.toFixed(2)
        let share1 = oldData[0].share1
        oldData[1].share1 = share1
        oldData[2].share1 = share1
        oldData[0].cashBackAmount = (parseFloat(groupSalesProfit0) * (share1.replace("%", "") / 100)).toFixed(2)
        oldData[1].cashBackAmount = (parseFloat(groupSalesProfit1) * (share1.replace("%", "") / 100)).toFixed(2)
        oldData[2].cashBackAmount = (parseFloat(groupSalesProfit2) * (share1.replace("%", "") / 100)).toFixed(2)
        let share2 = oldData[0].share2
        oldData[1].share2 = share2
        oldData[2].share2 = share2
        oldData[0].rebateAmount = (parseFloat(groupSalesProfit0) * (share2.replace("%", "") / 100)).toFixed(2)
        oldData[1].rebateAmount = (parseFloat(groupSalesProfit1) * (share2.replace("%", "") / 100)).toFixed(2)
        oldData[2].rebateAmount = (parseFloat(groupSalesProfit2) * (share2.replace("%", "") / 100)).toFixed(2)
        let share3 = oldData[0].share3
        oldData[1].share3 = share3
        oldData[2].share3 = share3
        oldData[0].rewardAmount = (parseFloat(groupSalesProfit0) * (share3.replace("%", "") / 100)).toFixed(2)
        oldData[1].rewardAmount = (parseFloat(groupSalesProfit1) * (share3.replace("%", "") / 100)).toFixed(2)
        oldData[2].rewardAmount = (parseFloat(groupSalesProfit2) * (share3.replace("%", "") / 100)).toFixed(2)
        tableIns.reload({
            data: oldData
        });
        tabledataIntoForm();
    }

    /**
     * 判断百分比是否等于100%
     */
    function judgePersent() {
        let cOroportion = parseFloat($('input[name="cOroportion"]').val().replace("%", ""))
        let oOroportion = parseFloat($('input[name="oOroportion"]').val().replace("%", ""))
        let pOroportion = parseFloat($('input[name="pOroportion"]').val().replace("%", ""))
        let percentageProfit = cOroportion + oOroportion + pOroportion
        if (percentageProfit != 100) {
            layui.use(['layer'], function () {
                let $ = layui.$, layer = layui.layer;
                layer.msg("利润分配比例总和需要等于100%噢！")
            })
            return false;
        }
        let oldData = viewObj.tbData;
        let share1 = parseFloat(oldData[0].share1.replace("%", ""))
        let share2 = parseFloat(oldData[0].share2.replace("%", ""))
        let share3 = parseFloat(oldData[0].share3.replace("%", ""))
        let share = share1 + share2 + share3
        if (share != 100) {
            layui.use(['layer'], function () {
                let $ = layui.$, layer = layui.layer;
                layer.msg("团销利润分配比例总和需要等于100%噢！")
            })
            return false;
        }
        return true;
    }

    /**
     * 清空商品详情（包括源代码）
     */
    function emptyDetails() {
        editor.txt.clear();
        $('input[name="detail"]').val('');
        layui.use(['layer'], function () {
            let $ = layui.$, layer = layui.layer;
            layer.msg("已清除！")
        })
    }

</script>
</body>
<style>
    /*去除颜色选择器的默认样式*/
    .layui-colorpicker-main-wrapper {
        display: none !important;
    }

    .layui-colorpicker-main-input .layui-inline {
        display: none !important;
    }


    .layui-colorpicker-main {
        width: 12% !important;
    }
</style>
</html>
